package com.videoweb.mapper;

import com.videoweb.entity.Video;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.videoweb.entity.dto.VideoItemDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;


/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author lmr
 * @since 2025-05-17
 */

@Mapper
public interface VideoMapper extends BaseMapper<Video> {

    void insertVideo(Video video);

//对频繁需要查询的数据写了视图：直接查，不用写得那么麻烦
    @Select("SELECT * FROM video_item;")
    public List<VideoItemDTO> findVideoItem();

//   findVideoByCategoryId    findVideoByTagID   findVideoByUserID    finVideoByVideoId
//          也可以直接where
@Select("SELECT * FROM video_item WHERE categoryId = #{categoryId} ;")
public List<VideoItemDTO> findVideoByCategoryId(Long categoryId);

    @Select("SELECT vi.* " +
            "FROM video_item vi " +
            "LEFT JOIN video_tag vt ON vt.video_id = vi.id " +
            "WHERE vt.tag_id = #{categoryId}")
    List<VideoItemDTO> findVideoByTagID(Long categoryId);


    @Select("SELECT * FROM video_item WHERE userId = #{userId} ;")
    public List<VideoItemDTO> findVideoByUserID(Long userId);



    public List<VideoItemDTO> findVideoByFavoritesId(Long favoriteId);




    @Select("SELECT * FROM video_item WHERE id = #{videoId} ;")
    public VideoItemDTO finVideoByVideoId(Long videoId);



}
